<template>
  <a-modal
    :open="open"
    width="850px"
    :title="props.rowData.bh ? '修改医嘱字典' : '新增医嘱字典'"
    centered
    ok-text="保存"
    destroy-on-close
    :keyboard="false"
    @ok="onOk"
    @cancel="onCancel"
  >
    <a-tabs v-model:activeKey="tabActiveKey">
      <a-tab-pane key="基本信息" tab="基本信息" />
      <a-tab-pane key="上海医保" tab="上海医保" />
    </a-tabs>
    <a-form v-if="tabActiveKey === '基本信息'" :model="formState" class="form-style-flex form-style-disabled">
      <a-form-item label="项目名称" class="w-1/2">
        <a-input v-model:value="formState.mc" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="票据名称" class="w-1/2">
        <a-input v-model:value="formState.receiptName" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="规格" class="w-1/2">
        <a-input v-model:value="formState.gg" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="助记码" class="w-1/2">
        <a-input v-model:value="formState.pyjm" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="单价" class="w-1/4">
        <a-input v-model:value="formState.dj" v-input-blur:float.3 v-input:float.3 placeholder="请输入" />
      </a-form-item>
      <a-form-item label="单位" class="w-1/4">
        <a-input v-model:value="formState.dw" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="会员类别" class="w-1/2">
        <SelectMember v-model:value="formState.memberCategoryCode" />
      </a-form-item>
      <a-form-item label="执行科室" class="w-1/2">
        <a-input v-model:value="formState.ksdms" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="项目类别" class="w-1/2">
        <a-select ref="select" v-model:value="formState.xmlb" :options="options" placeholder="请选择" allow-clear />
      </a-form-item>
      <a-form-item label="物价编码" class="w-1/2">
        <a-input v-model:value="formState.wjbm" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="病案类别" class="w-1/2">
        <a-input v-model:value="formState.mrCategoryName" placeholder="请输入" />
        />
      </a-form-item>
      <a-form-item label="统计类别" class="w-1/2">
        <SelectItem v-model:value="formState.statisticsCategoryId" type="DT00311" placeholder="请选择" allow-clear />
      </a-form-item>
      <a-form-item label="接口类别" class="w-full">
        <a-radio-group v-model:value="formState.jklb" :options="interfaceCategory" />
      </a-form-item>

      <!-- <a-form-item label="级别" class="w-1/2">
        <a-select ref="select" v-model:value="formState.level1" placeholder="请选择" allow-clear>
          <a-select-option :value="1">1</a-select-option>
          <a-select-option :value="2">2</a-select-option>
          <a-select-option :value="3">3</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="前缀" class="w-1/2">
        <a-input v-model:value="formState.prefix" placeholder="请输入" />
      </a-form-item> -->

      <a-form-item label="备注" class="w-full">
        <a-textarea v-model:value="formState.zysx" placeholder="请输入" :row="1" />
      </a-form-item>
    </a-form>
    <a-form
      v-if="tabActiveKey === '上海医保'"
      :model="formStateSH"
      class="form-style-flex h-[510px] content-start pr-4 mt-2"
      :label-col="{ style: { width: '120px' } }"
    >
      <a-form-item label="省医保码" class="w-1/2">
        <a-input v-model:value="formStateSH.lmiCode" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="物价编码" class="w-1/2">
        <a-input v-model:value="formStateSH.phCode" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="分类自付比例" class="w-1/2">
        <a-input v-model:value="formStateSH.rbmRatio" placeholder="请输入" suffix="%" />
      </a-form-item>
      <a-form-item label="医保限额" class="w-1/2">
        <div class="flex items-center">
          <a-switch v-model:checked="formStateSH.miLimitFlag" class="mr-4" :un-checked-value="0" :checked-value="1" />
          <a-input v-model:value="formStateSH.miLimit" placeholder="请输入" />
        </div>
      </a-form-item>
      <a-form-item label="英文名称" class="w-1/2">
        <a-input v-model:value="formStateSH.engName" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="医保限定" class="w-1/2">
        <div class="flex items-center">
          <a-switch v-model:checked="formStateSH.confineFlag" class="mr-4" :un-checked-value="0" :checked-value="1" />
          <div>项目细分 <a-switch v-model:checked="formStateSH.subFlag" :un-checked-value="0" :checked-value="1" /></div>
        </div>
      </a-form-item>
      <a-form-item label="备注" class="w-full">
        <a-textarea v-model:value="formStateSH.memo" placeholder="请输入" :row="5" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

const props = defineProps({
  open: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object,
    default: () => ({})
  }
})
const formStateSH = ref({})
const tabActiveKey = ref('上海医保')

const emit = defineEmits(['update:value', 'confirm', 'success'])
const options = ref([])
const interfaceCategory = [
  {
    label: '普通项目',
    value: 0
  },
  {
    label: '医技项目',
    value: 1
  },
  {
    label: '理疗项目',
    value: 3
  },
  {
    label: '检验项目',
    value: 4
  }
]
const formState = ref({
  jklb: 0,
  ksdms: null,
  receiptName: '',
  bh: '',
  pyjm: '',
  mc: '',
  dw: '',
  dj: 0,
  gg: '',
  xmlb: null,
  wjbm: '',
  zysx: ''
})

const onOk = async () => {
  const { code, msg } = await post('/operation/opex/shanghai/doSaveShmiDictAdviceItems', { ...props.rowData, ...formStateSH.value })
  if (code !== 0) return message.error(msg || '保存失败')
  message.success(msg)
  emit('success')
}
const onCancel = () => {
  emit('confirm')
}
watch(
  () => props.open,
  (val) => {
    if (val) {
      if (props.rowData?.bh) {
        formState.value = { ...props.rowData }
        formStateSH.value = { ...props.rowData }
      } else {
        formState.value = { jklb: 0, ksdms: null }
        formStateSH.value = {}
      }
    }
  }
)
</script>
<style lang="less" scoped>
.ant-form {
  display: flex;
  flex-flow: row wrap;
  min-width: 0;
  :deep(.ant-form-item) {
    .ant-form-item-label {
      width: 90px;
    }
  }
  .ant-picker {
    width: 100%;
  }
}
</style>
